package de.piratech.dasding.data.database.mongo.data;

import java.util.Date;

import net.vz.mongodb.jackson.DBRef;
import de.piratech.dasding.data.AbstractAction;
import de.piratech.dasding.data.database.mongo.AbstractMongoDB.COLLECTIONS;

public class AbstractMongoAction<T extends AbstractAction> extends
    AbstractMongoDataObject<T> {

  private DBRef<MongoUser, String> contactRef;
  private DBRef<MongoLocation, String> locationRef;
  private DBRef<MongoUser, String> responsibleRef;

  public AbstractMongoAction(T object) {
    super(object);
    if (object.getContact() != null) {
      contactRef = new DBRef<MongoUser, String>(object.getContact().getId(),
          COLLECTIONS.USER_COLLECTION.getName());
    }
    if (object.getLocation() != null) {
      locationRef = new DBRef<MongoLocation, String>(object.getLocation()
          .getId(), COLLECTIONS.LOCATION_COLLECTION.getName());
    }
    if (object.getResponsible() != null) {
      responsibleRef = new DBRef<MongoUser, String>(object.getResponsible()
          .getId(), COLLECTIONS.USER_COLLECTION.getName());
    }
  }

  public String getName() {
    return getDataObject().getName();
  }

  public void setName(String pName) {
    getDataObject().setName(pName);
  }

  public DBRef<MongoUser, String> getContactRef() {
    return contactRef;
  }

  public void setContactRef(DBRef<MongoUser, String> contactRef) {
    getDataObject().setContact(contactRef.fetch().getDataObject());
  }

  public String getDescription() {
    return getDataObject().getDescription();
  }

  public void setDescription(String pDescription) {
    getDataObject().setDescription(pDescription);
  }

  public String getFinalWords() {
    return getDataObject().getFinalWords();
  }

  public void setFinalWords(String pFinalWords) {
    getDataObject().setFinalWords(pFinalWords);
  }

  public String getFurtherInformation() {
    return getDataObject().getFurtherInformation();
  }

  public void setFurtherInformation(String pFurtherInformation) {
    getDataObject().setFurtherInformation(pFurtherInformation);
  }

  public DBRef<MongoLocation, String> getLocationRef() {
    return locationRef;
  }

  public void setLocationRef(DBRef<MongoLocation, String> locationRef) {
    getDataObject().setLocation(locationRef.fetch().getDataObject());
  }

  public DBRef<MongoUser, String> getResponsibleRef() {
    return responsibleRef;
  }

  public void setResponsibleRef(DBRef<MongoUser, String> responsibleRef) {
    this.responsibleRef = responsibleRef;
    getDataObject().setResponsible(responsibleRef.fetch().getDataObject());
  }

  public Date getTime() {
    return getDataObject().getTime();
  }

  public void setTime(Date pTime) {
    getDataObject().setTime(pTime);
  }
}
